package com.ellricky.newtv.adapter

import android.view.View
import android.widget.ImageView
import androidx.constraintlayout.widget.Group
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.ellricky.newtv.R
import com.ellricky.newtv.bean.TvCourseFile

const val TYPE_NORMAL = 1 //正常
const val TYPE_PREPARE = 2 //备课
const val TYPE_RECORD = 3 //记录

class CourseFileAdapter(val type: Int) :
    BaseQuickAdapter<TvCourseFile, BaseViewHolder>(R.layout.item_course_file) {
    override fun convert(holder: BaseViewHolder, item: TvCourseFile) {
        val ivCover = holder.itemView.findViewById<ImageView>(R.id.iv_cover)
        val viewCover = holder.itemView.findViewById<View>(R.id.view_cover2)
        val group = holder.itemView.findViewById<Group>(R.id.group_prepare)
        val groupRecord = holder.itemView.findViewById<Group>(R.id.group_record)
        Glide.with(context).load(item.ware_pptFistImg).into(ivCover)

        holder.setText(R.id.tv_course_name, item.ware_name)

        when (type) {
            TYPE_NORMAL -> {
                if (item.is_lock == 1) {
                    group.visibility = View.VISIBLE
                } else {
                    group.visibility = View.GONE
                }
            }
            TYPE_PREPARE -> {
                if (item.is_lock == 1) {
                    group.visibility = View.VISIBLE
                } else {
                    group.visibility = View.GONE
                }
            }
            TYPE_RECORD -> {
                if (item.look_time.isNotEmpty()) {
                    groupRecord.visibility = View.VISIBLE
                    holder.setText(R.id.tv_record_time, "最近浏览时间")
                    holder.setText(R.id.tv_record_time_detail, item.look_time)
                } else {
                    groupRecord.visibility = View.GONE
                }
                viewCover.isClickable = false
            }
        }
    }
}